﻿using System;
using System.Data;
using System.Data.SqlClient;
using ReportWizard.Helpers;

namespace ReportWizard.DataAccess
{
    public class ArchiveReportBaseObject
    {
        public int Id { get; set; }
        public int ArchiveReportId { get; set; }
        public int ReportBaseObjectId { get; set; }

        public ArchiveReportBaseObject(int archiveReportId, int reportBaseObjectId)
        {
            ArchiveReportId = archiveReportId;
            ReportBaseObjectId = reportBaseObjectId;
        }

        public void Insert()
        {
            try
            {
                using (SqlConnection con = CommonDb.GetOilWizardConection())
                {
                    SqlCommand saveCmd = new SqlCommand("ArchiveReportBaseObjectInsert", con);
                    saveCmd.CommandType = CommandType.StoredProcedure;

                    saveCmd.Parameters.Add("@ArchiveReportId", SqlDbType.Int).Value = ArchiveReportId;
                    saveCmd.Parameters.Add("@ReportBaseObjectId", SqlDbType.Int).Value = ReportBaseObjectId;
                    saveCmd.Parameters.Add("@Id", SqlDbType.Int).Direction = ParameterDirection.Output;

                    con.Open();
                    if (saveCmd.ExecuteNonQuery() != 0)
                    {
                        Id = Convert.ToInt32(saveCmd.Parameters["@Id"].Value);
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.WriteLog(ex);
            }
        }
    }
}